﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace OnePiece.Ui.Controls.HtmlHelpers
{
    public static class DropdownListControlHelper
    {
        public static string DropdownListControl<T, TResult>(this HtmlHelper helper, string name, IQueryable<T> query, Func<T, TResult> selectSelector, string dataValueField, string dataTextField, object htmlAttributes)
        {            
            var selectListItem = (new SelectList(
                query
                    .Select(selectSelector)
                    .AsEnumerable() 
                , dataValueField, dataTextField)).AsEnumerable();

            return helper.DropDownList(name, selectListItem, htmlAttributes);
        }

        public static string DropdownListControl<T, TResult>(this HtmlHelper helper, string name, Expression<Func<T, TResult>> expression , string dataValueField, string dataTextField)
        {
            //TODO: Research in using the Expression tree
            throw new NotImplementedException();

        }


    }
}